<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

        .ht {
            text-align: center;
            color: cadetblue;
            font-family: 幼圆;
        }

        .tab {
            width: 500px;
            border: 5px solid cadetblue;
            margin: 0px auto;
            border-radius: 5px;
            font-family: 幼圆;
        }

        .ltr td {
            border: 1px solid powderblue;

        }

        .ipt {
            border: 0px;
            width: 50%;

        }

        .btn1 {
            border: 2px solid powderblue;
            border-radius: 4px;
            width: 60px;
            background-color: antiquewhite;

        }

        #usernameMsg, #userPwdMsg {
            color: gold;
        }

        .buttonContainer {
            text-align: center;
        }
    </style>

    <script>

    </script>
</head>
<body>
<h1 class="ht">欢迎使用日程管理系统</h1>
<h3 class="ht">请登录</h3>
<form method="post" action="/user/login" onsubmit="return checkForm()">
    <table class="tab" cellspacing="0px">
        <tr class="ltr">
            <td>请输入账号</td>
            <td>
                <input class="ipt" type="text" id="usernameInput" name="username" onblur="checkUsername()">
                <span id="usernameMsg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td>请输入密码</td>
            <td>
                <input class="ipt" type="password" id="userPwdInput" name="userPwd" onblur="checkUserPwd()">
                <span id="userPwdMsg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td colspan="2" class="buttonContainer">
                <input class="btn1" type="submit" value="登录">
                <input class="btn1" type="reset" value="重置">
                <button class="btn1"><a href="/regist.html">去注册</a></button>
            </td>
        </tr>
    </table>
</form>
<script>
    //定义验证用户名是否合格的正则表达式方法
    function checkUsername() {
        //定义正则表达式(用户名)
        const regUsername = /^[a-zA-Z0-9_-]{4,16}$/;
        //获得用户名输入框的属性
        var inputName = document.querySelector('#usernameInput');
        var inputNameValue = inputName.value;
        //得到提示信息的框
        var usernameMsg = document.querySelector('#usernameMsg');
        //进行判断
        if (!regUsername.test(inputNameValue)) {
            usernameMsg.innerHTML = "<span style='color:red;'>用户名不可用</span>"
            return false
        } else {
            usernameMsg.innerHTML = "<span style='color:greenyellow;'>用户名可用</span>"
            return true
        }
    }

    ////定义验证密码是否合格的正则表达式方法
    function checkUserPwd() {
        //定义正则表达式(密码)
        const regUserPwd = /^[a-zA-Z0-9_-]{4,16}$/;
        //获得用户名输入框的属性
        var inputPwd = document.querySelector('#userPwdInput');
        var inputPwdValue = inputPwd.value;
        //得到提示信息的框
        var userPwdMsg = document.querySelector('#userPwdMsg');
        //进行判断
        if (!regUserPwd.test(inputPwdValue)) {
            userPwdMsg.innerHTML = "<span style='color:red;'>密码不可用</span>"
            return false
        } else {
            userPwdMsg.innerHTML = "<span style='color:greenyellow;'>密码可用</span>"
            return true
        }
    }

    //定义一个公共的方法 同时执行用户名的验证和密码的验证
    function checkForm() {
        checkUsername();
        checkUserPwd();
    }
</script>
</body>
</html>